﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dao
{
    public class IPCostoVariable : Intermediario
    {
        public override void save<T>(T entity)
        {
            try
            {
                CostosVariable cv = entity as CostosVariable;
                dao.CostosVariables.InsertOnSubmit(cv);
                dao.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("IPRCostosVariable.save - " + ex.Message);
            };
        }

        public override List<T> getAll<T>()
        {
            try
            {
                //return (from cf in dao.CostosVariables where cf.Activo == true select cf).ToList() as List<T>;
                return (from cf in dao.CostosVariables select cf).ToList() as List<T>;
            }
            catch (Exception)
            {                
                throw;
            };
        }

        public override List<T> getByCriterio<T>(string att, string op, string val)
        {
            return(from cv in dao.CostosVariables where cv.IdProducto == Convert.ToInt16(val) select cv).ToList() as List<T>;
        }

        public override IList<T> getCriterioById<T>(string att, string op, int val)
        {
            throw new NotImplementedException();
        }

        public override object getPorId(int id)
        {
            throw new NotImplementedException();
        }

        public override IList<T> getPorCriterio<T>(string name)
        {
            throw new NotImplementedException();
        }

        public override void Update<T>(T entity)
        {
            throw new NotImplementedException();
        }

        public override void Delete(int id)
        {
            try
            {
                CostosVariable cf = (from c in dao.CostosVariables where c.Id == id select c).SingleOrDefault();

                if (cf != null)
                {
                    //cf.Activo = false;
                    dao.SubmitChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
